package com.eightbears.beboy.base.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.eightbears.beboy.R;

/**
 * @创建者 Administrator
 * @创建时间 Created by Administrator on 2017/3/2.
 * @描述 自定义对话框(登陆后编辑对话框)
 * @更新 $Author$
 * @更新时间 2017/3/2
 * @更新描述 ${TODO}.
 */

public class EditDataDialog extends Dialog implements View.OnClickListener {
    private DialogEditNameListener mDialogNameListener = null;
    private TextView btn_editdialog_ensure, btn_cancel;
    private EditText et_editdialog_nickname;
    private ImageView iv_clear;
    private String tv_titleText;
    private String et_hintText;

    public void setTitleText(String text) {
        this.tv_titleText = text;
    }

    public void setEditHintText(String text) {
        this.et_hintText = text;
    }


    public EditDataDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    public EditDataDialog(Context context) {
        super(context, R.style.MyDialog);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_editdate);
        initView();
        initEvent();
        getWindow().setGravity(Gravity.CENTER);
        WindowManager.LayoutParams LayoutParams = getWindow().getAttributes();
        WindowManager m = getWindow().getWindowManager();
        Display d = m.getDefaultDisplay();
        WindowManager.LayoutParams p = getWindow().getAttributes();
        p.width = d.getWidth();
        getWindow().setAttributes(p);

    }

    public void setOnItemClickListener(DialogEditNameListener listener) {
        this.mDialogNameListener = listener;
    }


    private void initView() {
        btn_editdialog_ensure = (TextView) findViewById(R.id.btn_editdialog_ensure);
        btn_cancel = (TextView) findViewById(R.id.btn_cancel);
        et_editdialog_nickname = (EditText) findViewById(R.id.et_editdialog_nickname);
        iv_clear = (ImageView) findViewById(R.id.iv_clear);
        TextView order_text_1 = (TextView) findViewById(R.id.order_text_1);
        order_text_1.setText(tv_titleText);
        et_editdialog_nickname.setHint(et_hintText);
    }

    private void initEvent() {
        btn_editdialog_ensure.setOnClickListener(this);
        btn_cancel.setOnClickListener(this);
        iv_clear.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_editdialog_ensure:
                String name = et_editdialog_nickname.getText().toString().trim();
                mDialogNameListener.onSetDialogNumOneListener(v, name);
                et_editdialog_nickname.setText("");
                break;
            case R.id.btn_cancel:
                mDialogNameListener.onSetDialogNumOneListener(v, "");
                break;
            case R.id.iv_clear:
                et_editdialog_nickname.setText("");
                break;
            default:
                break;
        }

    }

    public interface DialogEditNameListener {
        void onSetDialogNumOneListener(View v, String name);
    }
}
